package com.springmvc.controller;

import java.util.ArrayList;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.springmvc.domain.Job;
import com.springmvc.domain.common.DataWrapper;
import com.springmvc.service.IJobService;

@Controller
public class TestController {

	private static Logger logger = Logger.getLogger(TestController.class);

	@Resource
	private IJobService jobService;

	@RequestMapping("/Test/test")
	public String execute(HttpServletRequest req, Model model) throws Exception {
		System.out.println("Hello Kettle!");

		// model.addAttribute("json",JSON.toJSONString(jobList));

		return "job";
	}

	@RequestMapping("/Test/GetAllJobs")
	@ResponseBody
	public ArrayList<Job> GetAllJobs() throws Exception {
		ArrayList<Job> jobList = this.jobService.GetAll();
		logger.info(JSON.toJSONString(jobList));

		return jobList;
	}

	@RequestMapping("/Test/ExecJobById")
	@ResponseBody
	public DataWrapper ExecJobById(int parJobID) throws Exception {
		DataWrapper ret = new DataWrapper();
		try {
			ret.setResult(this.jobService.ExecJobById(parJobID));
		} catch (Exception ex) {
			ret.setMessage(ex.getMessage());
		}
		return ret;
	}
}
